package com.tianji.learning.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.common.domain.query.PageQuery;
import com.tianji.learning.domain.dto.LearningPlanDTO;
import com.tianji.learning.domain.vo.LearningLessonVO;
import com.tianji.learning.domain.vo.LearningPlanPageVO;
import com.tianji.learning.service.ILearningLessonService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 学生课程表 前端控制器
 * </p>
 *
 * @author wxh
 * @since 2024-08-20
 */
@Api(tags = "我的课表相关接口")
@RestController
@RequestMapping("/lessons")
public class LearningLessonController {

    @Autowired
    private ILearningLessonService iLearningLessonService;

    /**
     * 1.分页查询我的课表
     *
     * @param query
     * @return
     */
    @ApiOperation("查询我的课表，排序字段 latest_learn_time:学习时间排序，create_time:购买时间排序")
    @GetMapping("/page")
    public PageDTO<LearningLessonVO> queryMyLessons(PageQuery query) {
        return iLearningLessonService.queryMyLessons(query);
    }

    /**
     * 2.查询我正在学习的课程
     *
     * @return
     */
    @GetMapping("/now")
    @ApiOperation("查询我正在学习的课程")
    public LearningLessonVO selectLerningLesson() {
        return iLearningLessonService.selectLerningLesson();
    }

    /**
     * 3.删除已失效的课程
     *
     * @param courseId
     */
    @DeleteMapping("/{courseId}")
    @ApiOperation("删除已失效或者退款的课程")
    public void deleteCourse(@PathVariable Long courseId) {
        iLearningLessonService.deleteCourse(courseId);
    }

    /**
     * 4.查询课程是否有效
     */
    @GetMapping("/{courseId}/valid")
    @ApiOperation("查询课程是否有效")
    public Long selectCourseValid(@PathVariable Long courseId) {
        return iLearningLessonService.selectCourseValid(courseId);
    }

    /**
     * 5.查询用户课表中指定课程状态
     */
    @GetMapping("/{courseId}")
    @ApiOperation("查询指定课程信息")
    public LearningLessonVO selectIsCourseValid(@PathVariable Long courseId) {
        return iLearningLessonService.selectIsCourseValid(courseId);
    }

    /**
     * 6.统计课程学习人数
     *
     * @param courseId 课程id
     * @return 学习人数
     */
    @GetMapping("/{courseId}/count")
    @ApiOperation("统计课程学习人数")
    public Integer countLearningLessonByCourse(@PathVariable("courseId") Long courseId) {
        return iLearningLessonService.countLearningLessonByCourse(courseId);
    }

    /**
     * 7.新增学习计划
     */
    @PostMapping("/plans")
    @ApiOperation("新增学习计划")
    public void addLearningPlan(@Valid @RequestBody LearningPlanDTO learningPlanDTO) {
        iLearningLessonService.addLearningPlan(learningPlanDTO);

    }

    /**
     * 8.查询我的学习计划
     */
    @GetMapping ("/plans")
    @ApiOperation("查询我的学习计划")
    public LearningPlanPageVO queryMyLearningPlan(PageQuery pageQuery) {
        LearningPlanPageVO learningPlanPageVO = iLearningLessonService.queryMyLearningPlan(pageQuery);
        return learningPlanPageVO;
    }
}